import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/themes/cvue/layout/index'

Vue.use(Router)
// 路由实例
const router = new Router({
  scrollBehavior (to, from, savedPosition) { // 路由滚动行为
    if (savedPosition) {
      return savedPosition
    } else {
      const position = {}
      if (to.hash) {
        position.selector = to.hash
      }
      if (to.matched.some(m => m.meta.scrollToTop)) {
        position.x = 0
        position.y = 0
      }
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve(position)
        }, 500)
      })
    }
  },
  routes: [
    {
      path: '/auth',
      name: 'Auth',
      component: () => import(/* webpackChunkName: "group-foo" */'../themes/cvue/layout/index'),
      children: [
        {
          path: 'index',
          name: '',
          component: () => import(/* webpackChunkName: "group-foo" */'../themes/cvue/views/auth/index.vue')
        }
      ]
    },
    {
      path: '/index',
      name: 'Home',
      component: () => import(/* webpackChunkName: "group-foo" */'../themes/cvue/layout/index'),
      children: [
        {
          path: 'home',
          name: '代理管理',
          component: () => import(/* webpackChunkName: "group-foo" */'../themes/cvue/views/agent/index.vue')
        }
      ]
    },
    {
      path: '/sysConfig',
      name: 'SysConfig',
      component: () => import(/* webpackChunkName: "group-foo" */'../themes/cvue/layout/index'),
      children: [
        {
          path: 'index',
          name: '代理配置',
          component: () => import(/* webpackChunkName: "group-foo" */'../themes/cvue/views/sysConfig/index.vue')
        }
      ]
    },
    {
      path: '/bole',
      name: 'Bole',
      component: () => import(/* webpackChunkName: "group-foo" */'../themes/cvue/layout/index'),
      children: [
        {
          path: 'index',
          name: '伯乐奖',
          component: () => import(/* webpackChunkName: "group-foo" */'../themes/cvue/views/bole/index.vue')
        }
      ]
    },
    {
      path: '/contribution',
      name: 'Contribution',
      component: () => import(/* webpackChunkName: "group-foo" */'../themes/cvue/layout/index'),
      children: [
        {
          path: 'index',
          name: '贡献奖',
          component: () => import(/* webpackChunkName: "group-foo" */'../themes/cvue/views/contribution/index.vue')
        }
      ]
    },
    {
      path: '/system',
      name: 'System',
      component: () => import(/* webpackChunkName: "group-foo" */'../themes/cvue/layout/index'),
      children: [
        {
          path: 'index',
          name: '系统用户管理',
          component: () => import(/* webpackChunkName: "group-foo" */'../themes/cvue/views/system/index.vue')
        },
        {
          path: 'role-index',
          name: '角色管理',
          component: () => import(/* webpackChunkName: "group-foo" */'../themes/cvue/views/system/roleIndex.vue')
        }
      ]
    },
    {
      path: '/',
      redirect: '/login'
    },
    {
      path: '/login',
      name: 'Login',
      component: () => import(/* webpackChunkName: "group-foo" */'../themes/login/Login')
    },
    {
      path: '*',
      redirect: '/error/404'
    },
    {
      path: '/error/403',
      name: 'Error403',
      component: () => import(/* webpackChunkName: "group-foo" */'../themes/error/403')
    },
    {
      path: '/error/404',
      name: 'Error404',
      component: () => import(/* webpackChunkName: "group-foo" */'../themes/error/404')
    }

  ]
})
export default router
